#!/bin/bash

while getopts 'p:s:d:' OPT; do
  case $OPT in
    p) parallelism=$OPTARG;;
    s) savePoint=$OPTARG;;
    d) dataId=$OPTARG;;
    ?) 
      echo 'unknown args.' 
      exit 1;;
  esac
done

if [ -z "${parallelism}" ]; then
  echo "-p is not allowed empty."
  exit 1;
fi

if [ -z "${dataId}" ]; then
  echo "-d is not allowed empty."
  exit 1;
fi

prefix_args="-p ${parallelism}"
if [ ! -z "${savePoint}" ]; then
  prefix_args="${prefix_args} -n -s ${savePoint}"
fi

echo "flink run ${prefix_args} job/data-cdc-job-1.0.0.jar --dataId ${dataId} --profile prod"
flink run ${prefix_args} job/data-cdc-job-1.0.0.jar --dataId ${dataId} --profile prod
